#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <assert.h>

int const BUF_SZ = 1024;

int str_cmp (int *s1, int *s2);

int main (int argc, char* argv[])
{
FILE *fin_1 = NULL, *fin_2 = NULL;
int *buf_1 = NULL, *buf_2 = NULL;
int i = 0, j = 0, asrt_ver_val = 0;

//allocating memory
buf_1 = (int*) calloc (BUF_SZ, sizeof (int));
assert (buf_1 != NULL);

buf_2 = (int*) calloc (BUF_SZ, sizeof (int));
assert (buf_2 != NULL);

//opening files
fin_1 = fopen (argv[1], "r");
assert (fin_1 != NULL);

fin_2 = fopen (argv[2], "r");
assert (fin_1 != NULL);

//putting strings to buffers
while ( ((i = fgetc (fin_1)) != EOF) && ((j = fgetc (fin_2)) != EOF) )
	{
	if (i != (int) NULL)
		{
		asrt_ver_val = ungetc (i, fin_1);
		assert (asrt_ver_val != (int) NULL);
		}
	
	//printf ("\n\ndebug\n\n");  //
	
	if (j != (int) NULL)
		{
		asrt_ver_val = ungetc (j, fin_2);
		assert (asrt_ver_val != (int) NULL);
		}
		
	//printf ("\n\ndebug\n\n");  //
	
	while ( (i = fgetc (fin_1)) != '\n')
		strcat ((char *) buf_1, (char *) &i);
	
	//printf ("\n\ndebug\n\n");  //
	
	while ( (i = fgetc (fin_2)) != '\n')
		strcat ((char *) buf_2, (char *) &i);
		
	//printf ("\n\ndebug\n\n");  //
	
	str_cmp (buf_1, buf_2);
	
	i = (int) NULL; j = (int) NULL;
	*buf_1 = '\0'; *buf_2 = '\0';
	}



//closing files
fclose (fin_1);
fin_1 = NULL;

fclose (fin_2);
fin_2 = NULL;

//giving freedom to allocated memory
free (buf_1);
buf_1 = NULL;

free (buf_2);
buf_2 = NULL;

return 0;
}

int str_cmp (int *s1, int *s2)
	{
	int cmp = 0;
	
	cmp = strcmp ((char *) s1, (char *) s2);
	if (cmp != 0)
		{
		printf ("s1: %s\n", (char *) s1);
		printf ("s2: %s\n\n", (char *) s2);
		return 1;
		}
	return 0;
	}

